home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1415 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: news.iag.net!news
  2. From: jatmon@iag.net (John R Buchan)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Constructor?
  5. Followup-To: comp.lang.c++
  6. Date: 13 Jan 1996 19:31:06 GMT
  7. Organization: Internet Access Group, Orlando, Florida
  8. Message-ID: <4d919q$pq2@news.iag.net>
  9. References: <00001a80+00006b6c@msn.com>
  10. NNTP-Posting-Host: pm2-orl3.iag.net
  11. X-Newsreader: WinVN 0.99.7
  12.  
  13. In article <00001a80+00006b6c@msn.com>, Pacu@msn.com says...
  14. >
  15. >In a program example, I saw something similar to the following:
  16. >
  17. >                public:
  18. >                        CString str;
  19. >                                (etc..)
  20.  
  21. I am assuming that this is inside of the declaration of a class or struct.
  22. I'll call it MyClass.
  23.  
  24. This is defining a member of this class named str as type CString.  No 
  25. constructor is called at this point.
  26.  
  27. The CString constructor will be called, when an object of type MyClass is 
  28. created (instanciated) at some point in the code, as with the CString object
  29. below. The process of creating the MyClass object creates a CString object, 
  30. since it is a member.  This necessitates calling the CString constructor.
  31.  
  32. >
  33. >
  34. >                Later, in a function, I saw: 
  35. >
  36. >                Function()
  37. >                                        
  38. >                        Cstring str;
  39.  
  40. This is defining an object named str of type CString.  The CString 
  41. constructor will be called, when this code is executed.
  42.  
  43.                          MyClass obj.
  44.  
  45. When executed, this will create a MyClass object.  The process will involve
  46. creating a CString object (the member str).
  47.  
  48. >                                (etc..)
  49. >
  50. >In episode one, is it declaring str to be of CString type or is it 
  51. >constructed there? And in the second instance, inside of the 
  52. >function, is it being constructed or is it a variable of CString 
  53. >type? If this example is too vague, I will try to find the missing 
  54. >pieces, but I ask it in a general sense concerning the nature of 
  55. >constuctors and variable tpe declaration. Any help is appreciated via 
  56. >personal e-mail. Pacu.
  57. >                        
  58.  
  59. This is definitely a C++ question, not C.  I'm quite rusty on C++, but
  60. I'm sure someone will correct any errors.  Followups are redirected to
  61. comp.lang.c++.
  62.  
  63. -- 
  64. John R Buchan           -:|:-     Looking for that elusive FAQ?  ftp to:
  65. jatmon@mail.iag.net     -:|:-     rtfm.mit.edu /pub/usenet-by-group/....
  66.  
  67.